var utils = require("./Utils")
var logger = require('../utils/logger').logger

exports.register = function (app) {
    app.get("/sign-in", function (req, res, next) {
        res.render("sign-in", {
            title: "登录视频系统"
        })
    })

    app.get("/sign-out", function (req, res, next) {
        logger.info("logout");
        utils.clearCookise(res);
        res.redirect("sign-in");
    })

    app.post("/sign-in", function (req, res, next) {
        var user = req.body.user
        logger.info(req.body);
        if (user && user.username === app.user.username && user.password === app.user.password) {
            utils.setCookie(res, user.username)
            res.redirect("/manage-video");
        } else {
            res.json({message: "用户名或密码不对,请重新登录"});
        }
    })
}